package org.club.common.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
public class RedisCheck {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @PostConstruct
    public void checkRedisConnection() {
        try {
            redisTemplate.getConnectionFactory().getConnection().ping();
            System.out.println("Redis 连接成功");
        } catch (Exception e) {
            throw new RuntimeException("Redis 服务不可用，请检查 Redis 是否已启动!!!! 启动命令:redis-server.exe");
        }
    }
}